package com.hcss.common.util;

import java.util.concurrent.TimeUnit;

/**
 * @function : 线程工具
 */
public class ThreadUtil {
	
	public static void main(String[] args){
		getMethodStackTrace();
	}
	
	public static void getMethodStackTrace(){
		StackTraceElement[] stacks = Thread.currentThread().getStackTrace();
		for(int i = 1; i < stacks.length; i++){
			StackTraceElement one = stacks[i];
			System.out.println(one.getClassName() + "." + one.getMethodName());
		}
	}
	
	/**
	 * 返回调用方法的名称
	 * @return
	 */
	public static String getCurrentMethodName(){
		return Thread.currentThread().getStackTrace()[2].getMethodName();
	}
	
	/**
	 * 暂停一段时间
	 * @param timeout
     * @param timeUnit 使用TimeUnit便于确认单位
	 */
	public static void sleep(long timeout, TimeUnit timeUnit){
		try {
            timeUnit.sleep(timeout);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
